package so.sao.code.service.web.tool;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import so.sao.code.service.service.impl.ThirdPartyCodeErrorResolveServiceImpl;

@Api(tags = "thirdCodeErrorResolve", value = "第三方码文件异常处理接口")
@RestController
@RequestMapping("/portal/thirdCode/errorResolve")
public class ThirdCodeResolveController {
	
	@Autowired
	ThirdPartyCodeErrorResolveServiceImpl thirdPartyCodeErrorResolveService;
	
	@ApiOperation(value = "根据数据库中文件记录id,修护错误", notes = "根据数据库中文件记录id,修护错误")
	@GetMapping(value = "/recordId/{recordId}",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity resolve(@PathVariable("recordId") Long recordId){
		thirdPartyCodeErrorResolveService.resolveTask(recordId, false);
		return new ResponseEntity<>(HttpStatus.OK);
	}
	
	
	//TODO 权限限制。
	@ApiOperation(value = "根据数据库中文件记录id,修护错误,强制执行，请不要随便使用", notes = "根据数据库中文件记录id,修护错误,强制执行，请不要随便使用")
	@GetMapping(value = "/recordId/{recordId}/force",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public ResponseEntity resolveForce(@PathVariable("recordId") Long recordId){
		
		thirdPartyCodeErrorResolveService.resolveTask(recordId, true);
		return new ResponseEntity<>(HttpStatus.OK);
	}
}
